<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
    <#assign base=request.contextPath  />
    <link rel="stylesheet" href="${base}/admin/MyStatic/frame/layui/css/layui.css?t=1534970980648" media="all">
    <script type="text/javascript" src="${base}/admin/MyStatic/js/zhang.js"></script>
    <script src="${base}/admin/MyStatic/frame/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${base}/admin/MyStatic/js/ztree/jquery-1.4.4.min.js"></script>
        <script type="text/javascript" src="${base}/admin/MyStatic/js/ztree/jquery.ztree.core.js"></script>
        <script type="text/javascript" src="${base}/admin/MyStatic/js/zhang.js"></script>
        <script type="text/javascript" src="${base}/admin/MyStatic/js/ztree/jquery.ztree.excheck.js"></script>
        <script type="text/javascript" src="${base}/admin/MyStatic/js/ztree/jquery.ztree.exedit.js"></script>
    <link rel="stylesheet" href="${base}/admin/MyStatic/css/demo.css" type="text/css">
    <link rel="stylesheet" href="${base}/admin/MyStatic/css/zTreeStyle.css" type="text/css">
    <style type="text/css">
		form{
		  padding:10px;
		}
        .layui-btn-radius{
            border-radius: 5px;
        }
		</style>
</head>
<body>
<form action="" class="layui-form">
    <div id="tankuang" style="margin-left: 20px;">
        <div class="layui-inline">
            <label class="layui-form-label"><i style="color:red">*</i>&nbsp;分销商名</label>
            <div class="layui-input-inline">
                <input name="number" lay-verify="required" autocomplete="off" class="layui-input" id="roleName" type="text">
            </div>
        </div>
        <div style="height: 300px;width:450px;">
            <label class="layui-form-label">选择该分销商可见菜单</label>

            <ul id="tree" class="ztree" style="width:300px; height: 280px; overflow:auto;border:1px solid #F0F9FF;background-color: #F0F9FF;"></ul>

        </div>
       <#-- <div class="layui-form-item">
            <label class="layui-form-label">首页板块:</label>
            <input type="checkbox" name="like[write]" class="bankuai" value="1033596882212941821" title="前台管理" >
            <input type="checkbox" name="like[write]" class="bankuai"  value="1033596952794636292" title="财务管理">
            <input type="checkbox" name="like[write]" class="bankuai" value="1033596952794636293" title="营销管理"><br/>
      &lt;#&ndash;      <input type="checkbox" name="like[write]" class="bankuai" value="1033596952794636294" title="产康预约">&ndash;&gt;
            <input type="checkbox" name="like[write]" class="bankuai" value="1033596952794636305" title="仓库管理">
            <input type="checkbox" name="like[write]" class="bankuai" value="1033596952794636296" title="人事管理">
        </div>-->
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-radius"type="button" onclick="submi()" lay-submit="" lay-filter=""style="background-color: #0092EF;">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary layui-btn-radius">重置</button>
        </div>
    </div>
</form>

<script>

layui.use(['form', 'layedit', 'laydate'], function(){
  var form = layui.form
  ,layer = layui.layer
  ,layedit = layui.layedit
  ,laydate = layui.laydate;
  form.on('submit(formDemo)', function(data){
    layer.msg(JSON.stringify(data.field));
    return false;
  });
});
var zTreeObj,
        setting = {

            view: {
                selectedMulti: false,
                showLine: true,
                dblClickExpand: false
            },

            callback: {
                //回调函数 默认展开节点
                onAsyncSuccess:
                        function(){
                            var treeObj = $.fn.zTree.getZTreeObj("tree");
                            treeObj.expandAll(true);
                        }

            } ,
            async: {
                enable: true,
                url: "${base}/admin/menu/findMenuZtreeByPeople"
            } ,
            data:{
                simpleData : {
                    enable : true,
                    idKey : "id",
                    pIdKey : "pId",
                    rootPid : 0
                }
            },
            check:{
                enable: true,
                chkStyle: "checkbox",
                radioType:"all",
                chkboxType: { "Y": "ps", "N": "ps" }
            }

        };
//初始化树
zTreeObj = $.fn.zTree.init($("#tree"), setting );


function submi(){
    if($("#roleName").val()==""){
        layer.msg("请输入分销商名！");
        return;
    }
    if(getAllID("tree")==""){
        layer.msg("请选择该分销商可见菜单！");
        return;
    }
  var a=  getAllID("tree");
/*    var id="";
    var name="";
    $("input:checkbox[name='like[write]']:checked").each(function() { // 遍历name=standard的多选框
        id += ',' + $(this).val();
        name += ',' + $(this).attr('title');
    });*/
    var rolename=$("#roleName").val();
    var requestJson={};
    requestJson.menuId=a;
    requestJson.roleName=rolename;
    $.ajax({
        type : "POST", //提交方式
        url : "${base}/admin/role/insertDistribution",//路径
        dataType:"json",
        data :requestJson,
        success : function(data) {//返回数据根据结果进行相应的处理
              if(data.code===0){
                  var table = parent.layui.table;
                  //表刷新方法
                  table.reload('testReload', {
                      url: '${base}/admin/role/findDistribution'
                      ,where: {} //设定异步数据接口的额外参数
                      //,height: 300
                  });
                  var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                  parent.layer.close(index); //再执行关闭
              }else{
                  layer.msg(data.msg)
              }

        }
    });
}
</script>
</body>

</html>
